package unit.collisions;

import unit.panels.AbstractPanel;

import com.golden.gamedev.object.Sprite;
import com.golden.gamedev.object.collision.CollisionGroup;

public class WalkerToPanelCollision extends CollisionGroup implements ICollide{

	@Override
	public void collided(Sprite walker, Sprite panel) {
		getInstance(panel.getImage().toString()).operate(panel);
	}

	@Override
	public void reverseDirection(Sprite object1) {
		object1.setSpeed(object1.getHorizontalSpeed()*-1, object1.getVerticalSpeed()*-1);
	}

	/*
	 * returns a new unspecified Panel Object
	 */
		@SuppressWarnings("unchecked")
		private AbstractPanel getInstance(String panelType) {
			Class<AbstractPanel> myClass = null;
			try {
				myClass = (Class<AbstractPanel>) Class.forName(panelType);
			} catch (ClassNotFoundException e1) {
				e1.printStackTrace();
			}
			AbstractPanel walker = null;
			try {
				walker = myClass.newInstance();
			} catch (InstantiationException e) {
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				e.printStackTrace();
			}
			return walker;
		}
}
